#pragma once

#include "{{entity.name}}.h"

{{ get_cpp_includes(entity) }}
namespace {{ namespace_name }} {

{% for attr in entity.ownedAttributes %}
{% if get_attr_is_primitive(attr) %}
const {{ get_attr_type(attr) }} {{ entity.name }}::{{ get_attr_identity(attr) }}_default_{{ get_attr_primitive_default(attr) }};
{% endif %}
{% endfor %}
{% if is_element_child(entity) %}
{{ entity.name }}::{{ entity.name }}(const QString& umlType)
    : {{ get_base_class(entity) }}(umlType) {}

{% endif %}
void {{entity.name}}::fromJson(const QJsonObject& json, QStringList& errorList) {
    if (json.isEmpty()) {
        return;
    }

{% for gen in entity.generalizations %}
    {{ get_gen_from_json(gen) }}
{% endfor %}
{% for attr in entity.ownedAttributes %}
    {{ get_attr_from_json(attr) }}
{% endfor %}
}

void {{entity.name}}::toJson(QJsonObject& json) {
{% for gen in entity.generalizations %}
    {{ get_gen_to_json(gen) }}
{% endfor %}
{% for attr in entity.ownedAttributes %}
    {{ get_attr_to_json(attr) }}
{% endfor %}
}

{% for op in entity.ownedOperations %}
{% if has_op_definition(op) and has_op(op) %}
/// <summary>
/// {{ get_op_identity(op) }}{{ get_comment(op.ownedComment) }}
/// </summary>{{ get_op_rules_comment(op) }}
{{ get_op_return_type(op) }} {{entity.name}}::{{ get_op_identity(op) }}({{ get_op_params(op) }}){{ get_op_const(op)}}
{
    {{ get_op_body(op) }}
}

{% endif %}
{% endfor %}
{% for attr in entity.ownedAttributes %}
{% if get_attr_has_getter(attr) %}
/// <summary>
/// {{ get_attr_identity(attr) }} getter{{ get_comment(attr.ownedComment, "") }}
/// </summary>
{{ get_attr_type(attr, false, true) }} {{entity.name}}::{{ get_attr_identity(attr) }}(){{ get_attr_getter_const(attr)}} {
    return {{ get_attr_identity(attr) }}_;
}

{% endif %}
{% if get_attr_has_setter(attr) %}
/// <summary>
/// {{ get_attr_identity(attr) }} setter{{ get_comment(attr.ownedComment, "") }}
/// </summary>
void {{entity.name}}::{{ get_setter_name(get_attr_identity(attr)) }}({{ get_attr_type(attr, true) }} value) {
    {{ get_attr_identity(attr) }}_ = value;
}

{% endif %}
{% endfor %}
} // namespace {{ namespace_name }}
